<template>
  <div class="container container_province">
    <!-- 筛选类型 -->
    <div class='filter'>

      <div @click='gettypeval(0)' class='item'>
        <text :class="mclass==0?'type':''">全部</text>
      </div>

      <div @click='gettypeval(2)' class='item'>
        <text :class="mclass==2?'type':''">视频</text>
      </div>

      <div @click='gettypeval(1)' class='item'>
        <text :class="mclass==1?'type':''">图片</text>
      </div>

    </div>
    <scroll-view :scroll-y="true" :style="{'height': clientHeight+'px'}" @scrolltolower="infinite_scroll">
      <!-- 素材列表 -->
      <div class='section_list' v-if="listarr.length>0">
        <div class='col'>
          <!-- 素材列表item -->
          <div @click='todetails(item.class,item.id)' :key="index" v-for="(item,index) in listarr" class='sec_item'>
            <div class='imgbox'>
              <img v-if="item.mini_url" :src='imgUrl+item.mini_url' />
              <div v-if="item.class == 2" class='mask'>
                <img src='https://img.ameimeika.com/active/1efc6d65c2d9cb1b0ffecd66a8a415f8.png' />
              </div>
            </div>
            <div class='title'>{{item.title}}</div>
          </div>
          <!-- 素材列表item end-->
        </div>
      </div>

      <!-- 占位符 -->
      <div v-else class='orderholder'>
        <img src='https://img.ameimeika.com/active/d6eb8722443cb0715bd805b8798587d7.png' />
        <div>暂无相关素材～</div>
      </div>
    </scroll-view>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
export default {
  data() {
    return {
      imgUrl: common.image_response,
      isshow: false, // 占位符

      listarr: [], // 素材列表
      page: 1,
      pageSize: 6,

      type: "", // 素材类别id
      province_id: "", // 省份id
      mclass: 0, //素材类型  0 全部  1 图片  2视频
      clientHeight: 0
    };
  },
  methods: {
    infinite_scroll() {
      this.page++;
      this.getdata();
    },
    getdata() {
      var data = {
        page: this.page,
        pageSize: this.pageSize,
        type: this.type,
        keyword: "",
        province_id: this.province_id,
        class: this.mclass
      };
      common.mmk_Loading(0);
      common.fly_post("/api/act/material/material_s_list", data, msg => {
        common.mmk_Loading(1);
        let res = msg.data;
        if (res.status_code == 0) {
          this.listarr = this.listarr.concat(res.data);
        } else {
          common.mmk_Loading(2, res.message);
        }
      });
    },
    //跳转详情
    todetails(classs, id) {
      var that = this;
      var mid = id;
      var classs = classs;
      wx.getStorage({
        key: "user_token",
        success: response => {
          //   已登录
          wx.navigateTo({
            url: `/pages/material_center/material_del/main?mid=${mid}&class=${classs}&page=${
              that.page
            }`
          });
        },
        fail: () => {
          //   未登录
          wx.navigateTo({
            url: "/pages/package_main/login/main"
          });
        },
        complete: () => {}
      });
    },
    // 选择类型
    gettypeval(tab) {
      var that = this;
      var mclass = tab;

      if (mclass == that.mclass) {
        return;
      }

      that.page = 1;
      that.listarr = [];
      that.mclass = mclass;

      //再次调用数据
      that.getdata();
    }
  },
  onLoad(options) {
    let that = this;
    wx.setNavigationBarTitle({
      title: options.title
    });
    this.location = options;
    wx.getSystemInfo({
      success: function(res) {
        // 获取可使用窗口宽度
        that.clientHeight = res.windowHeight;
      }
    });
    this.province_id = options.province_id;
    this.type = options.type;

    if (!options.type) {
      wx.showToast({
        title: "未获取素材类型",
        icon: "none",
        duration: 2000
      });
      setTimeout(function() {
        wx.navigateBack({
          delta: 1
        });
      }, 500);
      return;
    }

    if (options.type) {
      this.type = options.type;
      this.listarr = [];
      this.page = 1;
    }
this.mclass = 0
    // 获取列表数据
    this.getdata();
  },
  onShow() {},
  watch: {}
};
</script>

<style lang="less" scoped>
/* material_list.wxss */
.container_mlist {
  min-height: 100%;
}
/* 筛选类型 */
.filter {
  width: 100%;
  height: 44px;
  line-height: 44px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 101;
  background: #fff;
  border-top: 1px solid #f5f5f5;
  border-bottom: 1px solid #f5f5f5;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: #666;
  padding: 0 2% 0 0;
}
.filter .item {
  width: 30%;
  text-align: center;
}
.filter .item image {
  width: 10px;
  height: 10px;
  vertical-align: middle;
  margin-left: 5px;
}
.filter .item .type {
  color: #fe4489;
}

/* 类型下拉菜单 */
.downmask {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
}
.downmask .downlist {
  width: 100%;
  position: absolute;
  top: -200px;
  left: 0;
  text-align: center;
  font-size: 14px;
  /* transition: all 0.5s ease-in; */
}
.downmask .downlist view {
  height: 48px;
  line-height: 48px;
  border-top: 1px solid #f5f5f5;
  background: #fff;
  color: #444;
}
.downmask .downlist view:first-child {
  border-top: none;
}

/* 素材列表 */
.section_list {
  display: flex;
  margin-top: 5px;
  padding-top: 50px;
}
.section_list .col {
  width: 100%;
  columns: 2;
  flex-wrap: nowrap;
  box-sizing: border-box;
  padding: 0 4%;
}
.section_list .col_r {
  width: 45%;
  display: flex;
  flex-direction: column;
  padding: 0 4% 0 1%;
}
.section_list .sec_item {
  width: 100%;
  font-size: 0;
  margin-bottom: 15px;
  break-inside: avoid;
}
.section_list .sec_item .imgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
  text-align: center;
  position: relative;
}
.section_list .sec_item .imgbox .mask image {
  width: 40px;
  height: 40px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-20px) translateY(-20px);
}
.section_list .sec_item .minimgbox .mask image {
  width: 40px;
  height: 40px;
  opacity: 0.6;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-20px) translateY(-20px);
}
.section_list .sec_item .minimgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
  text-align: center;
  position: relative;
}
.section_list .sec_item .minimgbox image {
  width: 100%;
}
.section_list .sec_item .minimgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
  position: relative;
}
.section_list .sec_item .imgbox image {
  width: 100%;
  min-height: 10px;
}
.section_list .sec_item .title {
  font-size: 14px;
  color: #444;
  margin: 3% 0;
}
.section_list .sec_item .like_msg {
  display: flex;
  font-size: 10px;
  color: #999;
}
.section_list .sec_item .like_msg .favorite {
  height: 20px;
  line-height: 20px;
  width: 30%;
}
.section_list .sec_item .like_msg .comment {
  height: 20px;
  line-height: 20px;
  width: 30%;
}
.section_list .sec_item .like_msg .favorite image {
  width: 16px;
  height: 16px;
  vertical-align: top;
  margin-top: 2px;
}
.section_list .sec_item .like_msg .comment image {
  width: 15px;
  height: 15px;
  vertical-align: top;
  margin-top: 2px;
}

/* 占位符 */
.orderholder {
  width: 128px;
  height: 114px;
  position: absolute;
  top: 240px;
  left: 50%;
  transform: translateX(-57px);
}
.orderholder image {
  width: 100%;
  height: 100%;
}
.orderholder view {
  font-size: 14px;
  color: #666;
  text-align: center;
}
</style>

